package c2.cross.business.minecraft.data;

import c2.advanced.share.TableFacade;
import c2.advanced.business.base.KvData;
import cate.game.pvp.minecraft.data.MinecraftLayerData;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

@NoteClass("灵能矿洞跨服数据")
public class MinecraftMainKV extends KvData {
    @NoteField("是否关闭")
    public boolean close;
    @NoteField("下次开启时间")
    public long openTime;
    @NoteField("下次关闭时间")
    public long closeTime;
    @NoteField("层数数据")
    public Map<Integer, MinecraftLayerData> layers;
    @NoteField("玩家保护时间")
    public Map<String, Long> roleProtectTimeMap;

    /**
     * 初始化
     *
     * @param tableFacade 配置管理
     */
    public void initialize(TableFacade tableFacade) {
        if (layers == null) {
            layers = new HashMap<>();
        }
        if (roleProtectTimeMap == null) {
            roleProtectTimeMap = new HashMap<>();
        }
        // 读取配置生成数据
        layers.entrySet().removeIf(entry -> !tableFacade.minecraft.mine_area_base.rowsByLayer.containsKey(entry.getKey()));
        for (int layer : tableFacade.minecraft.mine_area_base.rowsByLayer.keySet()) {
            if (!layers.containsKey(layer)) {
                layers.put(layer, new MinecraftLayerData(layer));
            }
        }
        layers.values().forEach(layer -> layer.init(tableFacade.minecraft));
    }
}
